package org.feng.config;

import org.feng.filter.LogRequestAndResponseFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * webfilter配置
 *
 * @author feng
 */
@Configuration
public class WebFilterConfiguration {

    @Bean
    public FilterRegistrationBean<LogRequestAndResponseFilter> requestLogFilter(@Autowired WebFilterProperties webFilterProperties) {
        FilterRegistrationBean<LogRequestAndResponseFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new LogRequestAndResponseFilter(webFilterProperties.getSkipLogUrls()));
        // 拦截 "/dict" 开头的请求
        registrationBean.addUrlPatterns("/dict/*");
        // 执行顺序最靠前
        registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registrationBean;
    }
}
